# -*- coding: utf-8 -*
'''
    Created by XiaoInk at 2021/10/10 23:09:17
    Gitee: https://gitee.com/XiaoInk
'''

from app import redis
from app.logger import logging


def get(token: str) -> str or None:
    '''获取token'''
    try:
        return redis.get(f'FLASK-TOKEN-{token}').decode()
    except Exception as e:
        logging.error(e)


def set(token: str, val: str, exp: int):
    '''设置token
    :param token 令牌
    :param val 值
    :param exp 过期时间, s
    '''
    redis.set(f'FLASK-TOKEN-{token}', val, exp)


def expire(token: str, exp: int) -> bool:
    '''设置token过期时间'''
    return redis.expire(f'FLASK-TOKEN-{token}', exp)


def delete(token: str) -> int:
    '''删除token'''
    return redis.delete(f'FLASK-TOKEN-{token}')


if __name__ == '__main__':
    pass
